package org.arl.modem.transportARQ;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.List;

class DrawTimeline {
   public static void main(String args[]) {
      List<Long> SenderTx = new LinkedList<Long>();
      List<Long> SenderRx = new LinkedList<Long>();
      try {
         FileInputStream fstream = new FileInputStream(
         // "/home/rohit/Desktop/arl/mod1/modem-sim/logs/log-0.txt");
               "/home/rohit/Desktop/logs/tx1.txt");
         DataInputStream in = new DataInputStream(fstream);
         BufferedReader br = new BufferedReader(new InputStreamReader(in));
         FileWriter outFilestx = new FileWriter("/home/rohit/Desktop/sendertx");
         PrintWriter outstx = new PrintWriter(outFilestx);
         FileWriter outFilesrx = new FileWriter("/home/rohit/Desktop/senderrx");
         PrintWriter outsrx = new PrintWriter(outFilesrx);
         long l1 = 0;
         String strLine;
         while ((strLine = br.readLine()) != null) {
            // Print the content on the console
            if (strLine.contains("~PRX.PKT.TIME=")) {
               String s = strLine.split("~PRX.PKT.TIME=")[1].split(",")[0];
               l1 = Long.parseLong(s) - l1;
               System.out.println(l1);
               l1 = Long.parseLong(s);
               outsrx.println(s);
               SenderRx.add(Long.parseLong(s));
            }
            if (strLine.contains("~PTX.PKT.TIME=")) {
               String s = strLine.split("~PTX.PKT.TIME=")[1].split(",")[0];
               l1 = Long.parseLong(s) - l1;
               System.out.println(l1);
               l1 = Long.parseLong(s);
               outstx.println(s);
               SenderTx.add(Long.parseLong(s));
            }
         }
         outstx.close();
         outsrx.close();
         in.close();

         FileInputStream fstream2 = new FileInputStream(
         // "/home/rohit/Desktop/arl/mod2/modem-sim/logs/log-0.txt");
               "/home/rohit/Desktop/logs/rx1.txt");
         DataInputStream in2 = new DataInputStream(fstream2);
         BufferedReader br2 = new BufferedReader(new InputStreamReader(in2));
         FileWriter outFilertx = new FileWriter("/home/rohit/Desktop/recvtx");
         PrintWriter outrtx = new PrintWriter(outFilertx);
         FileWriter outFilerrx = new FileWriter("/home/rohit/Desktop/recvrx");
         PrintWriter outrrx = new PrintWriter(outFilerrx);

         String strLine2;
         while ((strLine2 = br2.readLine()) != null) {
            // Print the content on the console
            if (strLine2.contains("~PRX.PKT.TIME=")) {
               String s = strLine2.split("~PRX.PKT.TIME=")[1].split(",")[0];
               System.out.println(s);
               outrrx.println(s);
               SenderRx.add(Long.parseLong(s));
            }
            if (strLine2.contains("~PTX.PKT.TIME=")) {
               String s = strLine2.split("~PTX.PKT.TIME=")[1].split(",")[0];
               System.out.println(s);
               outrtx.println(s);
               SenderTx.add(Long.parseLong(s));
            }
         }
         outrrx.close();
         outrtx.close();
         in2.close();
      } catch (Exception e) {// Catch exception if any
         System.err.println("Error: " + e.getMessage());
      }
   }
}
